home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/tasks.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <devices/timer.h>
-
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/timer_protos.h>
-
- #define _USEOLDEXEC_
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/timer.h>
-
- #include "Timer_rev.h"
-
- __asm LONG Timer(register __a0 STRPTR argptr, register __d0 LONG arglen)
- {
- struct DosLibrary *DOSBase;
- struct Library *TimerBase;
-
- struct MsgPort *tp;
- struct timerequest *tr;
- struct timeval start, end;
- struct Task *task;
- LONG rc = RETURN_FAIL;
-
- if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library" VERSTAG " by Flavio Stanchina", 37))
- {
- /* Null-terminate command line */
- argptr[--arglen] = '\0';
-
- if(tp = CreateMsgPort())
- {
- if(tr = (struct timerequest *)CreateIORequest(tp, sizeof(struct timerequest)))
- {
- /* Use UNIT_MICROHZ if you want accuracy on short intervals */
- /* Use UNIT_VBLANK if you want stability over time and low overhead */
- if(OpenDevice("timer.device", UNIT_MICROHZ, tr, 0) == 0)
- {
- TimerBase = (struct Library *)tr->tr_node.io_Device;
-
- task = FindTask(NULL);
-
- /* Time command */
- GetSysTime(&start);
- rc = SystemTags(argptr,
- NP_StackSize, task->tc_SPUpper - task->tc_SPLower,
- TAG_END);
- GetSysTime(&end);
-
- /* Print result */
- SubTime(&end, &start);
- VPrintf("*** Time: %ld.%06ld secs\n", (LONG *)&end);
-
- CloseDevice((struct IORequest *)tr);
- }
- else PutStr("Can't open timer device\n");
-
- DeleteIORequest((struct IORequest *)tr);
- }
- DeleteMsgPort(tp);
- }
- CloseLibrary((struct Library *)DOSBase);
- }
-
- return rc;
- }
-